﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/MasterPage.master" AutoEventWireup="true" CodeFile="History.aspx.cs" Inherits="History" %>

<asp:Content ID="Content1" ContentPlaceHolderID="title" Runat="Server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>


<asp:Content ID="Content3" ContentPlaceHolderID="ContentBoxFloatRightPlaceHolder" Runat="Server">
    <div class="b-accountParams">
		    <div class="b-title">
			    <div class="wrap">
				    <div class="h3">Lịch sử mua hàng</div>
			    </div>
		    </div>

            <table class="tblStyle">
			    <colgroup>
				    <col width="250"/>
				    <col/>
				    <col width="90"/>
				    <col/>
                    <col />
				    <col/>
			    </colgroup>
                <tfoot>
                    <tr>
                        <td colspan="6">
<% 
    NhaKinhDoanhDataContext db = new NhaKinhDoanhDataContext();
    TaiKhoan tk = (TaiKhoan)Session["TaiKhoan"];
    var query = (from p in db.PhieuDatHangs
                 where p.MaKhachHang == tk.MaKhachHang
                 orderby p.NgayDatHang descending
                 select p);
    
    int curpage = 1;
    int nums = query.Count();
    int perpage = 5;

    int pages = nums / perpage;
    
    if (nums % perpage != 0)
    {
        pages += 1;
    }
    
    if (Request.QueryString["page"] != null)
    {
        curpage = int.Parse(Request.QueryString["page"]);
    }
%>
                        <p style="float:left"><b>Trang: </b> &nbsp
<% 
    for (int i = 1; i <= pages; i++)
    {
        if (curpage == i)
        {
%>
            <a href="#"><b><%= i %></b></a> &nbsp&nbsp
<%
        }
        else
        {
%>
            <a href="History.aspx?page=<%= i %>" style="text-decoration:none;"><%= i %></a> &nbsp
<%
        }
    }
%>
                           
</p>
                        </td>
                    </tr>
                </tfoot>
			    <tbody><tr>
				    <th class="alignLeft noWrap">Tên sản phẩm</th>
				    <th class="noWrap">Số lượng</th>
				    <th class="noWrap">Đơn giá (USD)</th>
				    <th class="noWrap">Ngày mua</th>
				    <th class="noWrap">Trạng thái</th>
				    <th class="noWrap">Xem lộ trình/Tải về</th>
			    </tr>

<%  
    foreach(PhieuDatHang pdh in query.Skip(perpage * (curpage - 1)).Take(perpage))
    {
        foreach (CTPhieuDatHang ct in pdh.CTPhieuDatHangs)
        {
%>
                <tr>
		            <td class="alignLeft"><%= ct.TaiLieu.ProductName %></td>
		            <td><%= ct.SoLuong %></td>
		            <td><%= ct.GiaBan %></td>
                    <td><%= pdh.NgayDatHang.ToShortDateString() %></td>
                    <td class="alignLeft">
<% 
    if (pdh.MaTinhTrang == 0)
    {
        Response.Write("Đang chờ duyệt");
    }
    else if (pdh.MaTinhTrang < 4)
    {
        Response.Write("Đang chờ giao hàng");
    }
    else
    {
        Response.Write(pdh.TTPhieuDatHang.TenTinhTrang);
    }
%>           
                    </td>
		            <td>
<% 
    if (ct.LoaiSanPham == 1 && pdh.MaTinhTrang==4)
    {
%>
                        <a href="Download.aspx?id=<%=ct.MaTaiLieu %>&cus=<%=pdh.MaKhachHang %>&ord=<%=pdh.MaPDH %>">Tải sản phẩm</a>
<%
    }
            
    if (ct.LoaiSanPham == 2 && pdh.MaTinhTrang == 4)
    {
%>
                        <a href="<%= pdh.LienKetTheoDoiVC %>" onclick="window.open('<%= pdh.LienKetTheoDoiVC %>'); return false;">Xem lộ trình</a>
<%
    }         
%>
                    </td>
	            </tr>
<% 
        }
    }
%>
		    </tbody></table>

            <br />
		        <div style="width:170px;" class="button-style btn-a">
                    <a href="Default.aspx"><i></i>Quay lại trang chủ</a>
                </div>
            <br />

		    <div class="clr"></div>

	    </div>
</asp:Content>